package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParamDTO> ListSpecParamsByCondition(Long cid, Long gid, Boolean isSearching) {

        QueryWrapper<SpecParam> queryWrapper = new QueryWrapper<SpecParam>()
                .eq(cid != null, "category_id", cid)
                .eq(gid != null, "group_id", gid)
                .eq(isSearching != null,"searching", isSearching);

        List<SpecParam> specParamList = this.list(queryWrapper);

        return SpecParamDTO.convertEntityList(specParamList);
    }

    @Override
    public void saveSpecParam(SpecParamDTO specParamDTO) {
        this.save(specParamDTO.toEntity(SpecParam.class));
    }

    @Override
    public void updateSpecParam(SpecParamDTO specParamDTO) {
        this.updateById(specParamDTO.toEntity(SpecParam.class));
    }
}